<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
            <el-form-item prop="employerName">
                <div style="display:flex;justify-content:flex-start">

                    <el-select v-model="value" placeholder="请选择">
                        <el-option label="姓名" value="1">
                        </el-option>
                        <el-option label="性别" value="2">
                        </el-option>
                        <el-option label="国家/地区" value="3">
                        </el-option>
                        <el-option label="手机号" value="4">
                        </el-option>
                        <el-option label="邮箱地址" value="5">
                        </el-option>
                    </el-select>
                    <el-input v-model="queryParams.employerName" :placeholder="$t('please_enter', { name: '' })
            " clearable @keyup.enter.native="handleQuery" />
                </div>
            </el-form-item>
            <el-form-item label="期望职位" prop="clientId">
                <el-select v-model="queryParams.clientId" :placeholder="$t('please_select', { name: $t('associated_client') })
            " filterable clearable>
                    <el-option v-for="dict in customList" :key="dict.id" :label="dict.clientName"
                        :value="dict.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="工作经验（年）" prop="chargePerson">
                <el-select v-model="queryParams.chargePerson" :placeholder="$t('please_select', { name: $t('contact_person') })
            " filterable clearable>
                    <el-option v-for="dict in allUserList" :key="dict.userId" :label="dict.nickName"
                        :value="dict.userId"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('search')
                    }}</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('reset') }}</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <!-- <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['employer:employerList:add']">{{ $t('add') }}</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-delete" size="mini" @click="handleBatcheDel"
                    v-hasPermi="['employer:employerList:add']">{{ $t('delete') }}</el-button>
            </el-col> -->
            <el-col :span="1.5">
                <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport"
                    v-hasPermi="['employer:employerList:import']">{{ $t('import') }}</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                    v-hasPermi="['employer:employerList:export']">{{ $t('export') }}</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange" border
            :max-height="tableHeight">
            <el-table-column type="selection" width="55">
            </el-table-column>
            <el-table-column type="index" width="55" label="序号">
            </el-table-column>
            <el-table-column label="姓名" align="center" prop="employerName" :show-overflow-tooltip="true" />
            <el-table-column label="性别" align="center" prop="" :show-overflow-tooltip="true" />
            <el-table-column label="头像" align="center" prop="" :show-overflow-tooltip="true" />
            <el-table-column label="国家/地区" align="center" prop="" :show-overflow-tooltip="true" />
            <el-table-column label="手机号" align="center" prop="phone" :show-overflow-tooltip="true" />
            <el-table-column label="邮箱地址" align="center" prop="email" :show-overflow-tooltip="true" />
            <el-table-column label="期望职位" align="center" prop="" :show-overflow-tooltip="true" />
            <el-table-column label="工作经验（年）" align="center" prop="" :show-overflow-tooltip="true" />
            <el-table-column label="注册时间" align="center" prop="" :show-overflow-tooltip="true" />
            <el-table-column :label="$t('action')" align="center" class-name="small-padding fixed-width" width="280"
                fixed="right">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" @click="handleView(scope.row)"
                        v-hasPermi="['employer:employerList:view']">详情</el-button>
                    <el-button size="mini" type="text" @click="handleViewResume(scope.row)"
                        v-hasPermi="['employer:employerList:view']">默认简历</el-button>


                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" :page-sizes="[10, 20, 30, 50, 100, 200]" />

        <!-- 添加或修改雇主对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="130px">
                <el-card class="box-card" style="margin-bottom: 20px">
                    <div slot="header" class="clearfix">
                        <span>{{ $t('basic_information') }}</span>
                    </div>
                    <el-row :gutter="20">
                        <el-col :span="24">
                            <el-col :span="16">
                                <el-form-item :label="$t('profie_picture')" prop="avatar">
                                    <image-upload v-model="form.avatar" :limit="1" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <span style="text-align: right">{{ $t('customManager') + '：' }}
                                    {{ form.chargePersonName }}</span>
                            </el-col>
                        </el-col>

                        <el-col :span="8">
                            <el-form-item :label="$t('employer_name')" prop="employerName">
                                <el-input @blur="checkName()" v-model="form.employerName" :placeholder="$t('please_enter', {
            name: $t('employer_name'),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('employer_code')" prop="employerCode">
                                <el-input v-model="form.employerCode" :placeholder="$t('please_enter', {
            name: $t('employer_code'),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('associated_client')" prop="clientId">
                                <el-select v-model="form.clientId" :placeholder="$t('please_select', {
            name: $t('associated_client'),
        })
            " filterable clearable>
                                    <el-option v-for="dict in customList" :key="dict.id" :label="dict.clientName"
                                        :value="dict.id"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('country_region')" prop="countryRegion">
                                <el-input v-model="form.countryRegion" :placeholder="$t('please_enter', {
            name: $t('country_region'),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('default_language')" prop="language">
                                <el-select v-model="form.language" :placeholder="$t('please_select', {
            name: $t('default_language'),
        })
            ">
                                    <el-option v-for="dict in dict.type.language_type" :key="dict.value"
                                        :label="dict.label" :value="dict.value"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="20">
                        <el-col :span="8">
                            <el-form-item :label="$t('legal_representative')" prop="legalPerson">
                                <el-input v-model="form.legalPerson" :placeholder="$t('please_enter', {
            name: $t('legal_representative'),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('license_type')" prop="certificateType">
                                <el-select v-model="form.certificateType" :placeholder="$t('please_select', {
            name: $t('license_type'),
        })
            ">
                                    <el-option v-for="dict in dict.type.id_card_type" :key="dict.value"
                                        :label="dict.label" :value="dict.value"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('license_number')" prop="certificateNumber">
                                <el-input v-model="form.certificateNumber" :placeholder="$t('please_enter', {
            name: $t('license_number'),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('office_address')" prop="officeAddress">
                                <el-input v-model="form.officeAddress" :placeholder="$t('please_enter', {
            name: $t('office_address'),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('contact_person')" prop="contactPerson">
                                <el-input v-model="form.contactPerson" :placeholder="$t('please_enter', {
            name: $t('contact_person'),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('contact_phone_number')" prop="contactPhone">
                                <el-input v-model="form.contactPhone" :placeholder="$t('please_enter', {
            name: $t('contact_phone_number'),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('email_address')" prop="email">
                                <el-input v-model="form.email" :placeholder="$t('please_enter', {
            name: $t('email_address'),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('business_license_number')" prop="licenseNum">
                                <el-input v-model="form.licenseNum" :placeholder="$t('please_enter', {
            name: $t('business_license_number'),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('fax_number')" prop="faxNumber">
                                <el-input v-model="form.faxNumber" :placeholder="$t('please_enter', {
            name: $t('fax_number'),
        })
            " />
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-card>
                <el-card class="box-card" style="margin-bottom: 20px">
                    <div slot="header" class="clearfix">
                        <span>{{ $t('bank_information') }}</span>
                    </div>
                    <el-row :gutter="20">
                        <el-col :span="8">
                            <el-form-item :label="$t('bank_account_number')" prop="bankDTO.bankAccount">
                                <el-input v-model="form.bankDTO.bankAccount" :placeholder="$t('please_enter', {
            name: $t('bank_account_number'),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('account_holder')" prop="bankDTO.accountHolder">
                                <el-input v-model="form.bankDTO.accountHolder" :placeholder="$t('please_enter', {
            name: $t('account_holder'),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('bank_code')" prop="bankDTO.bankCode">
                                <el-input v-model="form.bankDTO.bankCode" :placeholder="$t('please_enter', {
            name: $t('bank_code'),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('branch_code')" prop="bankDTO.branchCode">
                                <el-input v-model="form.bankDTO.branchCode" :placeholder="$t('please_enter', {
            name: $t('branch_code'),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('bank_name_of_opening_account')" prop="bankDTO.openingBank">
                                <el-input v-model="form.bankDTO.openingBank" :placeholder="$t('please_enter', {
            name: $t(
                'bank_name_of_opening_account'
            ),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('default_account')" prop="bankDTO.defaultAccount">
                                <el-select v-model="form.bankDTO.defaultAccount" :placeholder="$t('please_select', {
            name: $t('default_account'),
        })
            ">
                                    <el-option v-for="dict in dict.type.yes_or_no" :key="dict.value" :label="dict.label"
                                        :value="parseInt(dict.value)"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="16">
                            <el-form-item :label="$t('remarks')" prop="bankDTO.remark">
                                <el-input v-model="form.bankDTO.remark" :placeholder="$t('please_enter', {
            name: $t('remarks'),
        })
            " type="textarea" :rows="3" :show-word-limit="true" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-card>
                <el-card class="box-card" style="margin-bottom: 20px">
                    <div slot="header" class="clearfix">
                        <span>{{ $t('information_of_taxation_report') }}</span>
                    </div>
                    <el-row :gutter="20">
                        <el-col :span="8">
                            <el-form-item :label="$t('employer_signatory_name')" label-width="120px"
                                prop="signatoryName">
                                <el-input v-model="form.signatoryName" :placeholder="$t('please_enter', {
            name: $t('employer_signatory_name'),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('employer_address')" prop="employerAddress">
                                <el-input v-model="form.employerAddress" :placeholder="$t('please_enter', {
            name: $t('employer_address'),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('signatory_position')" prop="signatoryPost">
                                <el-input v-model="form.signatoryPost" :placeholder="$t('please_enter', {
            name: $t('signatory_position'),
        })
            " />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('employer_tax_file_number')" prop="employerFileNumber">
                                <el-input v-model="form.employerFileNumber" :placeholder="$t('please_enter', {
            name: $t(
                'employer_tax_file_number'
            ),
        })
            " />
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-card>
                <el-card class="box-card" style="margin-bottom: 20px">
                    <div slot="header" class="clearfix">
                        <span>{{ $t('settings') }}</span>
                    </div>
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item :label="$t('customer_service_specialist')" prop="chargePerson">
                                <el-input :placeholder="$t('please_select', {
            name: $t('contact_person'),
        })
            " v-model="form.chargePersonName" readonly>
                                    <el-button slot="append" icon="el-icon-search" @click="handleCheckHead"></el-button>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item :label="$t('service_order')" prop="serviceOrder">
                                <el-input :placeholder="$t('please_select', {
            name: $t('service_order'),
        })
            " v-model="form.serviceOrderName" readonly>
                                    <el-button slot="append" icon="el-icon-search"
                                        @click="handleCheckServiceUnit"></el-button>
                                </el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-card>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">{{
            $t('confirm')
        }}</el-button>
                <el-button @click="cancel">{{ $t('cancel') }}</el-button>
            </div>
        </el-dialog>

        <!-- 导入弹窗 -->
        <importModal ref="importModal" :title="$t('import')" downloadUrl="business/employer/downloadTemplate.do"
            uploadUrl="business/employer/importTemplate.do" :downloadName="$t('employer_management')"
            @refreshList="getList">
        </importModal>

        <!-- 选择负责人弹窗 -->
        <headModal ref="headModal" @setHeadData="setHeadData"></headModal>
        <!-- 雇主详情弹窗 -->
        <customerDetail ref="customerDetail"></customerDetail>

        <serviceUnitTypeModal ref="serviceUnitTypeModal" @setCheckData="setCheckServiceUnitType"></serviceUnitTypeModal>
        <!-- 查看弹窗 -->
        <chickView ref="viewPeople" @handleAddPeople="handleAddPeople" v-if="viewPeopleId"></chickView>
        <rulesTips ref="RulesTips" @handleSuccess="handleSuccess"></rulesTips>
    </div>
</template>

<script>
import {
    listUser,
    getUser,
    delUser,
    addUser,
    updateUser,
    userAble,
} from '@/api/custom/employerList';
// import chickView from './createdPeoSearch.vue';
// import rulesTips from './rules.vue';
import { allList, getOneEmployer } from '@/api/custom/customerList';
// import { getDockingPerson } from '@/api/system/user';
// import importModal from '@/views/components/custom/importModal.vue';
// import headModal from '@/views/components/custom/headModal.vue';
// import serviceUnitTypeModal from '@/views/components/custom/serviceUnitTypeModal.vue';
// import customerDetail from './detail.vue';
import { employerResetPwd } from "@/api/system/user";
var myregs =
    /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
export default {
    name: 'User',
    dicts: ['id_card_type', 'language_type', 'yes_or_no'],
    components: {
        // importModal,
        // headModal,
        // serviceUnitTypeModal,
        // customerDetail,
        // chickView,
        // rulesTips,
    },
    data() {
        var validatePass = (rule, value, callback) => {
            if (!value) {
                callback(
                    new Error(
                        this.$t('please_enter', {
                            name: this.$t('email_address'),
                        })
                    )
                );
            } else if (!myregs.test(value)) {
                callback(new Error(this.$t('correct_format')));
            } else {
                callback();
            }
        };
        var validatePhone = (rule, value, callback) => {
            if (!value) {
                callback(
                    new Error(
                        this.$t('please_enter', {
                            name: this.$t('contact_number'),
                        })
                    )
                );
            } else {
                callback();
            }
        };
        return {
            value: '',
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 雇主表格数据
            userList: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                employerName: null,
                chargePerson: null,
                clientId: null,
            },
            viewPeopleId: null,
            // 表单参数
            form: {
                bankDTO: {},
            },
            // 表单校验
            rules: {
                employerName: [
                    {
                        required: true,
                        message: this.$t('cannot_empty', {
                            name: this.$t('employer_name'),
                        }),
                        trigger: 'blur',
                    },
                ],
                employerCode: [
                    {
                        required: true,
                        message: this.$t('cannot_empty', {
                            name: this.$t('employer_code'),
                        }),
                        trigger: 'blur',
                    },
                ],
                email: [
                    {
                        validator: validatePass,
                        trigger: 'blur',
                        required: true,
                    },
                ],
                contactPhone: [
                    {
                        validator: validatePhone,
                        trigger: 'blur',
                        required: true,
                    },
                ],
                chargePerson: [
                    {
                        required: true,
                        message: this.$t('cannot_empty', {
                            name: this.$t('contact_person'),
                        }),
                        trigger: 'change',
                    },
                ],
                // serviceOrder: [
                //   {
                //     required: true,
                //     message: "服务单不能为空",
                //     trigger: "change",
                //   },
                // ],
            },
            checkHeadData: {},
            // 对接人集合
            allUserList: [],
            //客户集合
            customList: [],

        };
    },
    created() {
        this.getList();
    },
    methods: {
        handleViewResume(row){
            this.$router.push('/recruiter/resume')
        },
        handleBatcheDel() {
            if (this.ids.length === 0) return this.$message.warning(this.$t("please_select", { name: this.$t("data_source") }))
            this.handleDelete({})
        },
        /** 重置密码按钮操作 */
        handleReset(row) {
            const id = row.id;
            this.$modal
                .confirm(this.$t('customer_password'))
                .then(function () {
                    return employerResetPwd(id);
                })
                .then(() => {
                    this.$modal.msgSuccess(this.$t('operation_successful'));
                })
                .catch(() => { });
        },
        checkName() {
            let employerName = this.form.employerName;
            getOneEmployer({ employerName }).then((res) => {
                console.log('🐛 ~ getOneEmployer ~ res:', res);
                if (!res.data) {
                    let text =
                        this.$t('employer_name') + this.$t('already_exists');
                    this.$message.error(text);
                    this.form.employerName = '';
                }
            });
        },
        handleSuccess() {
            this.getList();
        },
        handleAddPeople() {
            this.getList();
        },
        /** 查询雇主列表 */
        getList() {
            this.loading = true;
            listUser(this.queryParams).then((response) => {
                this.userList = response.data.records;
                this.total = response.data.total;
                this.loading = false;
                //对接人集合
                this.getDockingAllUser();
                //客户集合
                this.getAllList();
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                employerName: null,
                employerCode: null,
                countryRegion: null,
                language: null,
                legalPerson: null,
                certificateType: null,
                officeAddress: null,
                contactPerson: null,
                faxNumber: null,
                createBy: null,
                createTime: null,
                updateBy: null,
                updateTime: null,
                clientId: null,
                fuserId: null,
                userId: null,
                avatar: null,
                certificateNumber: null,
                contactPhone: null,
                email: null,
                bankDTO: {
                    bankAccount: null,
                    accountHolder: null,
                    bankCode: null,
                    branchCode: null,
                    openingBank: null,
                    defaultAccount: null,
                    remark: null,
                    employerFileNumber: null,
                },
                chargePerson: null,
                serviceOrder: null,
                chargePersonName: null,
                serviceOrderName: null,
            };
            this.checkHeadData = [];
            this.resetForm('form');
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm('queryForm');
            this.handleQuery();
        },
        //获取对接人集合
        getDockingAllUser() {
            getDockingPerson({
                pageSize: 999,
            }).then((response) => {
                this.allUserList = response.data.records;
            });
        },
        //获取客户集合
        getAllList() {
            allList().then((response) => {
                this.customList = response.data;
            });
        },
        //客户id转name
        clientFormatter(item) {
            let principalName = '';
            this.customList.forEach((element) => {
                if (element.id == item.clientId) {
                    principalName = element.clientName;
                }
            });
            return principalName;
        },
        //对接人id转name
        communicatingFormatter(item) {
            let principalName = '';
            this.allUserList.forEach((element) => {
                if (element.userId == item.chargePerson) {
                    principalName = element.nickName;
                }
            });
            return principalName;
        },

        // 格式化负责人
        formatterUser(item) {
            this.allUserList.forEach((element) => {
                if (element.userId == item) {
                    this.checkHeadData.nickName = element.nickName;
                }
            });
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map((item) => item.id);
            this.single = selection.length !== 1;
            this.multiple = !selection.length;
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = this.$t('add_new_employer');
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            const id = row.id || this.ids;
            getUser(id).then((response) => {
                this.form = response.data;
                if (!this.form.bankDTO) this.$set(this.form, 'bankDTO', {});
                this.open = true;
                this.title = this.$t('edit');
            });
        },
        // 查看
        handleView(row) {
            this.reset();
            let obj = {
                topTitle: this.$t('view_employer'),
                row: row,
            };
            this.viewPeopleId = row.id;
            this.$nextTick(() => {
                this.$refs.viewPeople.handleChangeP(obj);
            });
        },
        // 权限
        handleLimit(row) {
            this.$refs.RulesTips.handleUrl(row);
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs['form'].validate((valid) => {
                if (valid) {
                    this.form.bankVO = this.form.bankDTO;
                    if (this.form.id != null) {
                        updateUser(this.form).then((response) => {
                            this.$modal.msgSuccess(
                                this.$t('operation_successful')
                            );
                            this.open = false;
                            this.getList();
                        });
                    } else {
                        addUser(this.form).then((response) => {
                            this.$modal.msgSuccess(
                                this.$t('operation_successful')
                            );
                            this.open = false;
                            this.getList();
                        });
                    }
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = row.id || this.ids;
            this.$modal
                .confirm(this.$t('delete_data'))
                .then(function () {
                    return delUser(ids);
                })
                .then(() => {
                    this.getList();
                    this.$modal.msgSuccess(this.$t('operation_successful'));
                })
                .catch(() => { });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download(
                'business/employer/export',
                {
                    ...this.queryParams,
                },
                `personnel_${new Date().getTime()}.xlsx`
            );
        },
        handleStop(row) {
            let name = '';
            if (row.status == '0') {
                name = this.$t('disable');
            } else {
                name = this.$t('enable');
            }
            this.$modal
                .confirm(this.$t('enable_disable_data', { name }))
                .then(function () {
                    return userAble(row.id);
                })
                .then(() => {
                    this.getList();
                    this.$modal.msgSuccess(this.$t('operation_successful'));
                })
                .catch(() => { });
        },
        /** 导入按钮操作 */
        handleImport() {
            this.$refs.importModal.showModal();
        },
        // 选择负责人
        handleCheckHead() {
            this.$refs.headModal.showModal();
        },
        handleCheckServiceUnit() {
            this.$refs.serviceUnitTypeModal.showModal();
        },
        setHeadData(value) {
            this.checkHeadData = value;
            if (value) {
                this.$set(this.form, 'chargePersonName', value.nickName);
                this.$set(this.form, 'chargePerson', value.userId);
            } else {
                this.$set(this.form, 'chargePersonName', null);
                this.$set(this.form, 'chargePerson', null);
            }
        },
        setCheckServiceUnitType(list) {
            if (list) {
                this.$set(
                    this.form,
                    'serviceOrderName',
                    list.map((item) => item.serviceOrderName).join(',')
                );
                this.$set(
                    this.form,
                    'serviceOrder',
                    list.map((item) => item.id).join(',')
                );
            } else {
                this.form.serviceOrder = null;
                this.form.serviceOrderName = null;
            }
        },
    },
};
</script>
<style scoped></style>
